export async function* selectionSort(array, compare, swap, set) {
    const n = array.length;
    
    for (let i = 0; i < n - 1; i++) {
        let minIndex = i;
        
        for (let j = i + 1; j < n; j++) {
            yield { type: 'compare', indices: [minIndex, j] };
            
            if (await compare(j, minIndex)) {
                minIndex = j;
            }
        }
        
        if (minIndex !== i) {
            yield { type: 'swap', indices: [i, minIndex] };
            await swap(i, minIndex);
        }
    }
    
    yield { type: 'complete' };
}